Hi, |
Re: Find Empty Excel Cell
Try this:
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objUsedRange, objRows
int iRow = 0
oleGet(objExcelSheet,"UsedRange",objUsedRange)
oleGet(objExcelSheet,"Rows",objRows)
oleGet(objExcelSheet,"Count",iRow)
return iRow+1
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Find Empty Excel Cell Mathias Mamsch - Tue Aug 21 10:49:04 EDT 2012
Try this:
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objUsedRange, objRows
int iRow = 0
oleGet(objExcelSheet,"UsedRange",objUsedRange)
oleGet(objExcelSheet,"Rows",objRows)
oleGet(objExcelSheet,"Count",iRow)
return iRow+1
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thanks |
Re: Find Empty Excel Cell josiah820 - Tue Aug 21 11:23:29 EDT 2012
This is a function which will not affect any global variable. It declares its own iRow variable. Instead it will return the new iRow, so you need to do: iRow = findNext...(...)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Find Empty Excel Cell I think it should be this:
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objUsedRange, objRows
int iRow = 0
oleGet(objExcelSheet,"UsedRange",objUsedRange)
oleGet(objUsedRange,"Rows",objRows)
oleGet(objRows,"Count",iRow)
return iRow+1
}
|
Re: Find Empty Excel Cell Mathias Mamsch - Tue Aug 21 17:18:05 EDT 2012
This is a function which will not affect any global variable. It declares its own iRow variable. Instead it will return the new iRow, so you need to do: iRow = findNext...(...)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thanks! Attachments attachment_14877987_Track_Changes.dxl |
Re: Find Empty Excel Cell SystemAdmin - Wed Aug 22 07:47:32 EDT 2012 I think it should be this:
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objUsedRange, objRows
int iRow = 0
oleGet(objExcelSheet,"UsedRange",objUsedRange)
oleGet(objUsedRange,"Rows",objRows)
oleGet(objRows,"Count",iRow)
return iRow+1
}
-Louie |
Re: Find Empty Excel Cell llandale - Wed Aug 22 10:10:16 EDT 2012
-Louie oleGet(objExcelSheet,"UsedRange",objUsedRange) oleGet(objExcelSheet,"Rows",objRows) ?? Thanks |
Re: Find Empty Excel Cell josiah820 - Wed Aug 22 10:23:27 EDT 2012 No, I'm thinking this:
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objUsedRange, objRows
int iRow = 0
oleGet(objExcelSheet,"UsedRange",objUsedRange)
oleGet(objUsedRange,"Rows",objRows)
oleGet(objRows,"Count",iRow)
delete(objUsedRange) // <<Inserted
delete(objRows) // <<Inserted
return iRow+1
}
|
Re: Find Empty Excel Cell llandale - Wed Aug 22 12:41:21 EDT 2012 No, I'm thinking this:
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objUsedRange, objRows
int iRow = 0
oleGet(objExcelSheet,"UsedRange",objUsedRange)
oleGet(objUsedRange,"Rows",objRows)
oleGet(objRows,"Count",iRow)
delete(objUsedRange) // <<Inserted
delete(objRows) // <<Inserted
return iRow+1
}
Thanks!! |
Re: Find Empty Excel Cell llandale - Wed Aug 22 12:41:21 EDT 2012 No, I'm thinking this:
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objUsedRange, objRows
int iRow = 0
oleGet(objExcelSheet,"UsedRange",objUsedRange)
oleGet(objUsedRange,"Rows",objRows)
oleGet(objRows,"Count",iRow)
delete(objUsedRange) // <<Inserted
delete(objRows) // <<Inserted
return iRow+1
}
|
Re: Find Empty Excel Cell josiah820 - Wed Aug 22 13:01:44 EDT 2012 Others:
-Louie Not sure what is going in with those dozens of TABs before your comments; makes the display 3 pages wide. Even with tab-stops of a paltry "2" characters it looks bad. |
Re: Find Empty Excel Cell llandale - Wed Aug 22 13:28:18 EDT 2012
-Louie Not sure what is going in with those dozens of TABs before your comments; makes the display 3 pages wide. Even with tab-stops of a paltry "2" characters it looks bad. And yeah, I know... It's so the comments are lined up. That's how my supervisor wants them. It's strange, but you gotta do what they want you to do, ya know? |
Re: Find Empty Excel Cell llandale - Wed Aug 22 13:28:18 EDT 2012
-Louie Not sure what is going in with those dozens of TABs before your comments; makes the display 3 pages wide. Even with tab-stops of a paltry "2" characters it looks bad. Attachments attachment_14878171_Track_Changes.dxl |
Re: Find Empty Excel Cell josiah820 - Wed Aug 22 13:51:19 EDT 2012 |
Re: Find Empty Excel Cell josiah820 - Wed Aug 22 13:51:19 EDT 2012 This program works completely, except for the findEmptyRow() method, in which the variable iRows is not being changed. Any idea what could be up? Thanks Attachments attachment_14878191_Track_Changes.dxl |
Re: Find Empty Excel Cell llandale - Wed Aug 22 14:29:22 EDT 2012 |
Re: Find Empty Excel Cell josiah820 - Wed Aug 22 13:04:49 EDT 2012 oleCloseAutoObject(OleAutoObj&) |
Re: Find Empty Excel Cell josiah820 - Wed Aug 22 14:31:09 EDT 2012 |
Re: Find Empty Excel Cell josiah820 - Wed Aug 22 14:30:00 EDT 2012
Sorry I posted that findLastRow Message from some post on the internet without trying it. Adamarla is right, UsedRange is no way to go. A fairly slow but working example is here:
OleAutoObj wbs
OleAutoObj wb
OleAutoObj ws
OleAutoObj objCell
OleAutoArgs args = create
void openExcel() {
OleAutoObj ex = oleCreateAutoObject "Excel.Application"
oleGet (ex, "Workbooks", wbs)
oleMethod (wbs, "Add", args, wb)
olePut(ex, "Visible", true)
put(args, 1)
oleGet (ex, "Worksheets", args, ws)
}
void pasteString (int y, int x, string s) {
clear args
put (args, y)
put (args, x)
oleGet (ws, "Cells", args, objCell) // select cell
clear args
put (args, objCell)
copyToClipboard s
print oleMethod (ws, "Paste",args)
}
// VBA code taken from here: http://www.dbforums.com/microsoft-excel/1654111-find-next-empty-row.html
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objRange, objRow
OleAutoArgs args = create()
oleGet(objExcelSheet,"Cells",args, objRange)
int iRow = 0
clear args
put (args, "What", "*")
put (args, "SearchOrder", 1) // xlByRows
put (args, "SearchDirection", 2) // xlPrevious
oleMethod(objRange,"Find",args, objRow)
if (null objRow) oleGet(objRange, "Row", iRow)
else (oleGet(objRow,"Row",iRow))
delete args
oleCloseAutoObject objRange
oleCloseAutoObject objRow
return iRow+1
}
openExcel()
int i; for (i = 0; i < 10; i++) {
int iNext = findEmptyRow(ws)
pasteString (iNext, 1, "Hello")
iNext = findEmptyRow(ws)
pasteString (iNext, 2, "World!")
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Find Empty Excel Cell Mathias Mamsch - Thu Aug 23 03:43:01 EDT 2012
Sorry I posted that findLastRow Message from some post on the internet without trying it. Adamarla is right, UsedRange is no way to go. A fairly slow but working example is here:
OleAutoObj wbs
OleAutoObj wb
OleAutoObj ws
OleAutoObj objCell
OleAutoArgs args = create
void openExcel() {
OleAutoObj ex = oleCreateAutoObject "Excel.Application"
oleGet (ex, "Workbooks", wbs)
oleMethod (wbs, "Add", args, wb)
olePut(ex, "Visible", true)
put(args, 1)
oleGet (ex, "Worksheets", args, ws)
}
void pasteString (int y, int x, string s) {
clear args
put (args, y)
put (args, x)
oleGet (ws, "Cells", args, objCell) // select cell
clear args
put (args, objCell)
copyToClipboard s
print oleMethod (ws, "Paste",args)
}
// VBA code taken from here: http://www.dbforums.com/microsoft-excel/1654111-find-next-empty-row.html
int findEmptyRow (OleAutoObj objExcelSheet)
{
OleAutoObj objRange, objRow
OleAutoArgs args = create()
oleGet(objExcelSheet,"Cells",args, objRange)
int iRow = 0
clear args
put (args, "What", "*")
put (args, "SearchOrder", 1) // xlByRows
put (args, "SearchDirection", 2) // xlPrevious
oleMethod(objRange,"Find",args, objRow)
if (null objRow) oleGet(objRange, "Row", iRow)
else (oleGet(objRow,"Row",iRow))
delete args
oleCloseAutoObject objRange
oleCloseAutoObject objRow
return iRow+1
}
openExcel()
int i; for (i = 0; i < 10; i++) {
int iNext = findEmptyRow(ws)
pasteString (iNext, 1, "Hello")
iNext = findEmptyRow(ws)
pasteString (iNext, 2, "World!")
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|